package com.hand.liut.controller;

import com.hand.liut.entity.CommonResult;
import com.hand.liut.entity.Payment;
import com.hand.liut.service.PaymentService;
import javax.annotation.Resource;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: lxx
 * @Description: TODO
 * @DateTime: 2022/7/15 20:15
 **/
@RestController
public class PaymentController {

  @Resource
  private PaymentService paymentService;
  @Value("${server.port}")
  private String serverport;
  public static final String PAYMENT_SRV = "http://CLOUD-PAYMENT-SERVICE";

  /**
   * @Author: lxx
   * @Description: TODO
   * @DateTime: 2022/7/15 20:19
   * @Params:
   * @Return:
   **/
  @PostMapping("/create")
  public CommonResult create(@RequestBody Payment payment) {
    int result = paymentService.create(payment);
    if (result > 0) {
      CommonResult commomResult = new CommonResult(200, "添加成功" + "服务端口" + serverport, payment);
      return commomResult;
    } else {
      CommonResult commomResult = new CommonResult(500, "添加失败" + "服务端口" + serverport, null);
      return commomResult;
    }
  }

  /**
   * @Author: lxx
   * @Description: TODO
   * @DateTime: 2022/7/15 20:23
   * @Params:
   * @Return:
   **/
  @GetMapping("/find/{id}")
  public CommonResult<Payment> findById(@PathVariable("id") Long id) {
    Payment payment = paymentService.findById(id);
    System.out.println(payment);
    System.out.println("**热部署成功**");
    if (payment == null) {
      CommonResult commomResult = new CommonResult(500, "查找失败" + "服务端口" + serverport, null);
      return commomResult;
    } else {
      CommonResult commomResult = new CommonResult(200, "查找成功" + "服务端口" + serverport, payment);
      return commomResult;
    }
  }
}
